package com.xcity.game.battle.pve;

import java.util.ArrayList;
import java.util.List;

import com.xcity.db.entity.Player;
import com.xcity.game.common.ItemResponse;
import com.xcity.game.item.drop.listener.ExpDropListener;
import com.xcity.game.item.drop.listener.GoldDropListener;
import com.xcity.game.item.drop.listener.ItemDropListener;

public class PVEStageDropListener implements ItemDropListener, GoldDropListener, ExpDropListener{

	private int money = 0;//-1;
	private int exp = 0;//-1;
	private List<ItemResponse> items;
	@Override
	public void goldDroped(Player player, int val) {
		//钱
//		if(money == -1){
//			money = 0;
//		}
		money = money + val;
	}
	
	@Override
	public void expDroped(Player player, int val) {
		//经验
//		if(exp == -1){
//			exp = 0;
//		}
		exp = exp + val;
	}

	@Override
	public void itemDroped(Player player, int itemId, int count) {
		if(items == null){
			items = new ArrayList<>();
		}
		boolean isSame = false;
		for(int i = items.size() - 1;i > -1; i--){
			ItemResponse itemres = items.get(i);
			if(itemId == itemres.getId()){
				itemres.setCount(itemres.getCount() + count);
				isSame = true;
			}
		}
		if(!isSame){
			items.add(new ItemResponse(itemId, count));
		}
		
	}
	public List<ItemResponse> getItems() {
		return items;
	}
	public int getMoney() {
		return money;
	}
	public int getExp() {
		return exp;
	}

}
